﻿/*
' DotNetNuke® - http://www.dotnetnuke.com
' Copyright (c) 2002-2009
' by DotNetNuke Corporation
'
' Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
' documentation files (the "Software"), to deal in the Software without restriction, including without limitation 
' the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and 
' to permit persons to whom the Software is furnished to do so, subject to the following conditions:
'
' The above copyright notice and this permission notice shall be included in all copies or substantial portions 
' of the Software.
'
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 
' TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
' THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
' CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
' DEALINGS IN THE SOFTWARE.
*/

using System;
using MbUnit.Framework;
using WatiN.Core;
using DotNetNuke.Tests.UI.WatiN.Common;
using DotNetNuke.Tests.UI.WatiN.Utilities;
using DotNetNuke.Tests.UI.WatiN.Common.WatiNObjects;
using System.IO;
using System.Text.RegularExpressions;



namespace DotNetNuke.Tests.UI.WatiN.RegressionTests
{
    [TestFixture]


    public class FiveFourTwoTests : RTBase
    {

        #region Test Setup and TearDown

        public bool LanguagePackInstalled = false;

        [SetUp]
        public void SetUp()
        {

        }

        [TearDown]
        public void TearDown()
        {
           TearDownTest();
        }

        #endregion

        #region Tests

        [Test]
        public void DNN_11696_Notifications_Event_Log_Email_Notifications_Dont_Work()
        {
            //Arrange
            SetUpTestForInstall();
            RunAutoInstall();
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);

            //Delete any files in the test EmailAddress folder
            homePage.DeleteFilesInTestEmails();

            //Edit the web.config file so that Emails are sent to a local folder
            WebConfigManager.UpdateConfig(PhysicalPath);
                        
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/Host/Host%20Settings.aspx");
            HostSettingsPage hostSettings = new HostSettingsPage(homePage);
            hostSettings.SetSchedularToTimerMethod("support@dnn.com");
            System.Threading.Thread.Sleep(1000);
            hostSettings.SetSMTPSettings("support@dnn.com", "localhost");

            //Act 
            ieInstance.GoTo(SiteURL + "/Host/Schedule.aspx");
            SchedulePage schedule = new SchedulePage(homePage);
            schedule.GetScheduleItemEditButton("Send Log Notifications").Click();
            schedule.EnableEventCheckbox.Checked = true;
            schedule.TimeLapseTextField.Value = "15";
            schedule.TimeLapseMeasurementSelectList.Select("Seconds");
            schedule.UpdateLink.Click();

            ieInstance.GoTo(SiteURL + "/Admin/LogViewer.aspx");
            EventViewerPage eventViewer = new EventViewerPage(homePage);
            eventViewer.EditLogSettingsLink.Click();
            System.Threading.Thread.Sleep(1000);
            eventViewer.GetLogTypeEditButton("HOST_ALERT").Click();
            System.Threading.Thread.Sleep(1500);

            eventViewer.EnableLoggingCheckbox.Checked = true;
            eventViewer.KeepMostRecentEntriesSelectList.Select("100 Log Entries");
            eventViewer.EmailNotificationEnabledCheckbox.Checked = true;
            eventViewer.MailFromAddressField.Value = "support@dnn.com";
            eventViewer.MailToAddressField.Value = "host@dnn.com";
            eventViewer.UpdateLink.Click();

            //Assert 
            System.Threading.Thread.Sleep(2000);
            ieInstance.GoTo(SiteURL + "/Host/Host%20Settings.aspx");
            hostSettings.RestartApplicationLink.Click();

            System.Threading.Thread.Sleep(60000);
            //Assert that the EmailAddress text is correct

            String emailFileName = null;
            String emailContent = null;
            int emailFilePosition = 0;
            for (int i = 0; i < Directory.GetFiles(TestEmailPath).Length; i++)
            {
                emailFileName = Directory.GetFiles(TestEmailPath)[i];
                emailContent = File.ReadAllText(emailFileName);
                if (emailContent.Contains("X-Receiver: " + TestUsers.Host.Email) && emailContent.Contains("X-Sender: support@dnn.com"))
                {
                    emailFilePosition = i;
                }
            }


            emailFileName = Directory.GetFiles(TestEmailPath)[emailFilePosition];
            emailContent = File.ReadAllText(emailFileName);
            String decodedEmailContent = ConvertEmailContentFromBase64ToUnicode(emailContent, emailFileName);
            Assert.IsTrue(decodedEmailContent.Contains("User triggered an Application Restart"), "Looking at string: " + decodedEmailContent);

        }

        
        [Test]
        public void DNN_11996_No_Subject_Title_In_Password_Reminders_Admin_Changes()
        {
            //Arrange
            SetUpTestForInstall();
            RunAutoInstall();
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);

            //Delete any files in the test EmailAddress folder
            homePage.DeleteFilesInTestEmails();

            //Edit the web.config file so that Emails are sent to a local folder
            WebConfigManager.UpdateConfig(PhysicalPath);

            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/Host/Host%20Settings.aspx");
            HostSettingsPage hostSettings = new HostSettingsPage(homePage);
            hostSettings.SetSMTPSettings("support@dnn.com", "localhost");

            //Add Users
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            loginPage.LogoffUser();
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
            ieInstance.GoTo(SiteURL + "/Admin/UserAccounts.aspx");
            UserPage userPage = new UserPage(homePage);
            userPage.AddUser(TestUsers.User1.UserName, TestUsers.User1.Password, TestUsers.User1.FirstName, TestUsers.User1.LastName, TestUsers.User1.EmailAddress, TestUsers.User1.DisplayName);
            System.Threading.Thread.Sleep(2000);
            //Delete any files in the test EmailAddress folder
            homePage.DeleteFilesInTestEmails();
            userPage.GetUserEditButton(TestUsers.User1.DisplayName).Click();

            string newPassword = "newPass";
            userPage.ManagePasswordLink.Click();
            System.Threading.Thread.Sleep(1500);
            userPage.NewPasswordTextField.Value = newPassword;
            userPage.ConfirmNewPasswordField.Value = newPassword;
            userPage.ChangePasswordLink.Click();

            //Check for the change password EmailAddress
            String emailFileName = null;
            String emailContent = null;
            int emailFilePosition = 0;
            for (int i = 0; i < Directory.GetFiles(TestEmailPath).Length; i++)
            {
                emailFileName = Directory.GetFiles(TestEmailPath)[i];
                emailContent = File.ReadAllText(emailFileName);
                if (emailContent.Contains("X-Receiver: " + TestUsers.User1.EmailAddress) && emailContent.Contains("X-Sender: " + TestUsers.Admin.Email))
                {
                    emailFilePosition = i;
                }
            }
            
            emailFileName = Directory.GetFiles(TestEmailPath)[emailFilePosition];
            emailContent = File.ReadAllText(emailFileName);
            String decodedEmailContent = ConvertEmailContentFromBase64ToUnicode(emailContent, emailFileName);
            Assert.IsTrue(decodedEmailContent.Contains("You have requested a Password Reminder from My Website."), "Looking at string: " + decodedEmailContent);
            Assert.IsTrue(decodedEmailContent.Contains("Password: " + newPassword), "Looking at string: " + decodedEmailContent);
            String decodedEmailSubject = ConvertEmailSubjectFromBase64ToUnicode(emailContent, emailFileName);
            Assert.IsTrue(decodedEmailSubject.Contains("My Website Password Reminder"), "Looking at string: " + decodedEmailSubject);
        }

        [Test]
        public void DNN_11996_No_Subject_Title_In_Password_Reminders_Host_Changes()
        {
            //Arrange
            SetUpTestForInstall();
            RunAutoInstall();
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);

            //Delete any files in the test EmailAddress folder
            homePage.DeleteFilesInTestEmails();

            //Edit the web.config file so that Emails are sent to a local folder
            WebConfigManager.UpdateConfig(PhysicalPath);

            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/Host/Host%20Settings.aspx");
            HostSettingsPage hostSettings = new HostSettingsPage(homePage);
            hostSettings.SetSMTPSettings("support@dnn.com", "localhost");

            //Add Users
            ieInstance.GoTo(SiteURL + "/Admin/UserAccounts.aspx");
            UserPage userPage = new UserPage(homePage);
            userPage.AddUser(TestUsers.User1.UserName, TestUsers.User1.Password, TestUsers.User1.FirstName, TestUsers.User1.LastName, TestUsers.User1.EmailAddress, TestUsers.User1.DisplayName);
            System.Threading.Thread.Sleep(2000);
            //Delete any files in the test EmailAddress folder
            homePage.DeleteFilesInTestEmails();
            userPage.GetUserEditButton(TestUsers.User1.DisplayName).Click();

            string newPassword = "newPass";
            userPage.ManagePasswordLink.Click();
            System.Threading.Thread.Sleep(1500);
            userPage.NewPasswordTextField.Value = newPassword;
            userPage.ConfirmNewPasswordField.Value = newPassword;
            userPage.ChangePasswordLink.Click();

            //Check for the change password EmailAddress
            String emailFileName = null;
            String emailContent = null;
            int emailFilePosition = 0;
            for (int i = 0; i < Directory.GetFiles(TestEmailPath).Length; i++)
            {
                emailFileName = Directory.GetFiles(TestEmailPath)[i];
                emailContent = File.ReadAllText(emailFileName);
                if (emailContent.Contains("X-Receiver: " + TestUsers.User1.EmailAddress) && emailContent.Contains("X-Sender: " + TestUsers.Admin.Email))
                {
                    emailFilePosition = i;
                }
            }

            emailFileName = Directory.GetFiles(TestEmailPath)[emailFilePosition];
            emailContent = File.ReadAllText(emailFileName);
            String decodedEmailContent = ConvertEmailContentFromBase64ToUnicode(emailContent, emailFileName);
            Assert.IsTrue(decodedEmailContent.Contains("You have requested a Password Reminder from My Website."), "Looking at string: " + decodedEmailContent);
            Assert.IsTrue(decodedEmailContent.Contains("Password: " + newPassword), "Looking at string: " + decodedEmailContent);
            String decodedEmailSubject = ConvertEmailSubjectFromBase64ToUnicode(emailContent, emailFileName);
            Assert.IsTrue(decodedEmailSubject.Contains("My Website Password Reminder"), "Looking at string: " + decodedEmailSubject);
        }

        [Test]
        public void DNN_11996_No_Subject_Title_In_Password_Reminders_User_Changes()
        {
            //Arrange
            SetUpTestForInstall();
            RunAutoInstall();
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            UserPage userPage = new UserPage(homePage);

            //Delete any files in the test EmailAddress folder
            homePage.DeleteFilesInTestEmails();

            //Edit the web.config file so that Emails are sent to a local folder
            WebConfigManager.UpdateConfig(PhysicalPath);

            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/Host/Host%20Settings.aspx");
            HostSettingsPage hostSettings = new HostSettingsPage(homePage);
            hostSettings.SetSMTPSettings("support@dnn.com", "localhost");

            System.Threading.Thread.Sleep(1000);
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            loginPage.LogoffUser();
            System.Threading.Thread.Sleep(1000);

            //Act 
            //register users
            loginPage.RegisterLink.Click();
            userPage.RegisterUser(TestUsers.Register.UserName, TestUsers.Register.Password, TestUsers.Register.FirstName, TestUsers.Register.LastName, TestUsers.Register.EmailAddress, TestUsers.Register.DisplayName);
            System.Threading.Thread.Sleep(2000);
            //Delete any files in the test EmailAddress folder
            homePage.DeleteFilesInTestEmails();
           
            //Change the users password
            loginPage.RegisterLink.Click();
            UserProfilePage profilePage = new UserProfilePage(homePage);
            profilePage.EditProfileLink.Click();
            profilePage.ManagePasswordLink.Click();
            profilePage.CurrentPasswordField.Value = TestUsers.Register.Password;
            profilePage.NewPasswordField.Value = TestUsers.Register.NewPassword;
            profilePage.ConfirmNewPasswordField.Value = TestUsers.Register.NewPassword;
            profilePage.ChangePasswordLink.Click();
            System.Threading.Thread.Sleep(5000);


            //Check for the change password EmailAddress
            String emailFileName = null;
            String emailContent = null;
            int emailFilePosition = 0;
            for (int i = 0; i < Directory.GetFiles(TestEmailPath).Length; i++)
            {
                emailFileName = Directory.GetFiles(TestEmailPath)[i];
                emailContent = File.ReadAllText(emailFileName);
                if (emailContent.Contains("X-Receiver: " + TestUsers.Register.EmailAddress) && emailContent.Contains("X-Sender: " + TestUsers.Admin.Email))
                {
                    emailFilePosition = i;
                }
            }

            emailFileName = Directory.GetFiles(TestEmailPath)[emailFilePosition];
            emailContent = File.ReadAllText(emailFileName);
            String decodedEmailContent = ConvertEmailContentFromBase64ToUnicode(emailContent, emailFileName);
            Assert.IsTrue(decodedEmailContent.Contains("You have changed your Password on My Website."), "Looking at string: " + decodedEmailContent);
            Assert.IsTrue(decodedEmailContent.Contains("Password: " + TestUsers.Register.NewPassword), "Looking at string: " + decodedEmailContent);
    }

        [Test]
        public void DNN_12033_Admin_Vendors_Notification_Sent_Out_From_Wrong_Email_Address()
        {
            //Arrange
            SetUpTestForInstall();
            RunAutoInstall();
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);

            //Delete any files in the test EmailAddress folder
            homePage.DeleteFilesInTestEmails();

            //Edit the web.config file so that Emails are sent to a local folder
            WebConfigManager.UpdateConfig(PhysicalPath);

            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/Host/Host%20Settings.aspx");
            HostSettingsPage hostSettings = new HostSettingsPage(homePage);
            hostSettings.SetSMTPSettings("support@dnn.com", "localhost");

            //Act 
            System.Threading.Thread.Sleep(1000);
            ieInstance.GoTo(SiteURL + "/Admin/Vendors.aspx");
            VendorsPage vendors = new VendorsPage(homePage);
            vendors.AddNewVendor("Test1", "TestFN", "VendorLN", "test1@vendor.com", "aStreet", "Acity", "Canada", "t9i 4k8", "888-8888");
            System.Threading.Thread.Sleep(3000);

            //Assert
            //Check for email notification
            String emailFileName = null;
            String emailContent = null;
            int adminEmailFilePosition = 0;
            int vendorEmailFilePosition = 0;
            for (int i = 0; i < Directory.GetFiles(TestEmailPath).Length; i++)
            {
                emailFileName = Directory.GetFiles(TestEmailPath)[i];
                emailContent = File.ReadAllText(emailFileName);
                if (emailContent.Contains("X-Receiver: " + TestUsers.Admin.Email) && emailContent.Contains("X-Sender: " + TestUsers.Admin.Email))
                {
                    adminEmailFilePosition = i;
                }
                if (emailContent.Contains("X-Receiver: test1@vendor.com") && emailContent.Contains(("X-Sender: " + TestUsers.Admin.Email)))
                {

                    vendorEmailFilePosition = i;
                }
            }
            //View admin email content
            emailFileName = Directory.GetFiles(TestEmailPath)[adminEmailFilePosition];
            emailContent = File.ReadAllText(emailFileName);
            String decodedEmailContent = ConvertEmailContentFromBase64ToUnicode(emailContent, emailFileName);
            Assert.IsTrue(decodedEmailContent.Contains("Vendor Name: Test1"), "Looking at string: " + decodedEmailContent);
            Assert.IsTrue(decodedEmailContent.Contains("First Name: TestFN"), "Looking at string: " + decodedEmailContent);
            Assert.IsTrue(decodedEmailContent.Contains("Last Name: VendorLN"), "Looking at string: " + decodedEmailContent);
            String decodedEmailSubject = ConvertEmailSubjectFromBase64ToUnicode(emailContent, emailFileName);
            Assert.IsTrue(decodedEmailSubject.Contains("My Website Vendor Application"));

            //View vendor email Content
            emailFileName = Directory.GetFiles(TestEmailPath)[vendorEmailFilePosition];
            emailContent = File.ReadAllText(emailFileName);
            decodedEmailContent = ConvertEmailContentFromBase64ToUnicode(emailContent, emailFileName);
            Assert.IsTrue(decodedEmailContent.Contains("Dear TestFN VendorLN,"),"looking at string: " + decodedEmailContent);
            Assert.IsTrue(decodedEmailContent.Contains("Test1, has been successfully registered at My Website."), "Looking at string: " + decodedEmailContent);
            decodedEmailSubject = ConvertEmailSubjectFromBase64ToUnicode(emailContent, emailFileName);
            Assert.IsTrue(decodedEmailSubject.Contains("My Website Vendor Application"));
        }

        [Test]
        public void DNN_12154_Issue_Upgrading_From_523_To_531()
        {
            //Arrange
            SetUpgradeVersionAndType("493", "1");
            SetUpSiteForUpgrade();
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);

            //Act 
            System.Threading.Thread.Sleep(2000);
            //Login as host
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            //Install a language pack
            ieInstance.GoTo(SiteURL + "/Admin/Languages.aspx");
            LanguagePage languagePage = new LanguagePage(homePage);
            languagePage.InstallLanguagePackLink.Click();
            languagePage.LanguagePackFileUpload.Set(LanguagePath);
            languagePage.InstallLanguagePackLink.Click();
            System.Threading.Thread.Sleep(2000);
            languagePage.ReturnLink.Click();

            //Change the site default language
            ieInstance.GoTo(SiteURL + "/Admin/SiteSettings.aspx");
            System.Threading.Thread.Sleep(1500);
            SiteSettingsPage settingsPage = new SiteSettingsPage(homePage);
            settingsPage.AdvancedSettingsButton.Click();
            settingsPage.OtherSettingsExpandImage.Click();
            settingsPage.DefaultLocaleSelectList.Select(LocaleName);
            settingsPage.OldUpdateLink.Click();
            System.Threading.Thread.Sleep(1500);

            //logout and upgrade
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            loginPage.LogoffUser();
            ieInstance.Close();
            RunUpgrade();

            //Assert
            //Log in
            homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            //View the Event Viewer
            ieInstance.GoTo(SiteURL + "/Admin/LogViewer.aspx");
            EventViewerPage eventViewer = new EventViewerPage(homePage);
            Assert.IsFalse(eventViewer.LogViewerTable.InnerHtml.Contains("General Exception"));
        }

        [Test]
        public void DNN_12180_User_Can_See_Pages_They_Dont_Have_Permissions_For()
        {
            //Arrange
            SetUpTestForInstall();
            RunAutoInstall();
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);

            //Log in as Host
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);

            //Act
            //Add a page 
            RibbonBar ribbonBar = new RibbonBar(homePage);
            ribbonBar.NewPageLink.Click();
            PageSettingsPage page = new PageSettingsPage(homePage);
            page.AddPage("Test Page");

            //Add a User
            ieInstance.GoTo(SiteURL + "/Admin/UserAccounts.aspx");
            UserPage userPage = new UserPage(homePage);
            userPage.AddUser(TestUsers.User1.UserName, TestUsers.User1.Password, TestUsers.User1.FirstName, TestUsers.User1.LastName, TestUsers.User1.EmailAddress, TestUsers.User1.DisplayName);
            System.Threading.Thread.Sleep(2000);
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            loginPage.LogoffUser();

            //Log in as the user 
            loginPage.LoginUser(TestUsers.User1.UserName, TestUsers.User1.Password);
            loginPage.RegisterLink.Click();
            MessagingModule messagingModule = new MessagingModule(homePage);
            messagingModule.ComposeLink.Click();
            messagingModule.TelerikEditor.HyperLinkManager.Click();
            System.Threading.Thread.Sleep(1000);
            messagingModule.TelerikEditor.HyperlinkPageSelectLink.Click();

            //Assert 
            System.Threading.Thread.Sleep(1000);
            Assert.IsFalse(messagingModule.TelerikEditor.HyperlinkPageSelectList.InnerHtml.Contains("Test Page"));
        }

        [Test]
        public void DNN_12323_Child_Portal_No_Email_Sent_When_New_User_Registers()
        {
            //Arrange
            SetUpTestForInstall();
            RunAutoInstall();
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);

            //Delete any files in the test EmailAddress folder
            homePage.DeleteFilesInTestEmails();

            //Edit the web.config file so that Emails are sent to a local folder
            WebConfigManager.UpdateConfig(PhysicalPath);

            //Act 
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/Host/Host%20Settings.aspx");
            HostSettingsPage hostSettings = new HostSettingsPage(homePage);
            hostSettings.SetSMTPSettings("support@dnn.com", "localhost");

            //Add a language
            ieInstance.GoTo(SiteURL + "/Admin/Extensions.aspx");
            ExtensionsPage extensionsPage = new ExtensionsPage(homePage);
            extensionsPage.InstallExtension(LanguagePath);

            //Change the default Language
            ieInstance.GoTo(SiteURL + "/Admin/Languages.aspx");
            LanguagePage languagePage = new LanguagePage(homePage);
            languagePage.SelectAndUpdateNewDefaultLanguage(LocaleName, "rcbItem ");

            //Create a child portal
            ieInstance.GoTo(SiteURL + "/Host/Portals.aspx");
            HostPortalPage portalPage = new HostPortalPage(homePage);
            portalPage.AddChildPortalDontClickMsgLink(ApplicationName, "Child Portal", "ChildPortal");
            loginPage.LogoffUser();

            ieInstance.GoTo(SiteURL + "/ChildPortal");
            UserPage userPage = new UserPage(homePage);
            userPage.RegisterUser(TestUsers.Register.UserName, TestUsers.Register.Password, TestUsers.Register.FirstName, TestUsers.Register.LastName, TestUsers.Register.EmailAddress, TestUsers.Register.DisplayName);
            System.Threading.Thread.Sleep(1000);

            //Assert
            Assert.AreEqual(TestUsers.Register.DisplayName, userPage.RegisterLink.Text);
           
            //Check that an email was sent 
            String emailFileName = null;
            String emailContent = null;
            int adminEmailFilePosition = 0;
            int userEmailFilePosition = 0;
            for (int i = 0; i < Directory.GetFiles(TestEmailPath).Length; i++)
            {
                emailFileName = Directory.GetFiles(TestEmailPath)[i];
                emailContent = File.ReadAllText(emailFileName);
                if (emailContent.Contains("X-Receiver: " + TestUsers.Admin.Email) && emailContent.Contains("X-Sender: " + TestUsers.Admin.Email))
                {
                    adminEmailFilePosition = i;
                }
                if (emailContent.Contains("X-Receiver: " + TestUsers.Register.EmailAddress) && emailContent.Contains(("X-Sender: " + TestUsers.Admin.Email)))
                {

                    userEmailFilePosition = i;
                }
            }
            //View admin email content
            emailFileName = Directory.GetFiles(TestEmailPath)[adminEmailFilePosition];
            emailContent = File.ReadAllText(emailFileName);
            String decodedEmailContent = ConvertEmailContentFromBase64ToUnicode(emailContent, emailFileName);
            Assert.IsTrue(decodedEmailContent.Contains("First Name: " + TestUsers.Register.FirstName), "Looking at string: " + decodedEmailContent);
            Assert.IsTrue(decodedEmailContent.Contains("Last Name: " + TestUsers.Register.LastName), "Looking at string: " + decodedEmailContent);
            String decodedEmailSubject = ConvertEmailSubjectFromBase64ToUnicode(emailContent, emailFileName);
            Assert.IsTrue(decodedEmailSubject.Contains("My Website New User Registration"));
           
            //View vendor email Content
            emailFileName = Directory.GetFiles(TestEmailPath)[userEmailFilePosition];
            emailContent = File.ReadAllText(emailFileName);
            decodedEmailContent = ConvertEmailContentFromBase64ToUnicode(emailContent, emailFileName);
            Assert.IsTrue(decodedEmailContent.Contains("Cher(??re) " + TestUsers.Register.DisplayName), "looking at string: " + decodedEmailContent);
            Assert.IsTrue(decodedEmailContent.Contains("nous avons le plaisir de vous informer que vous avez ??t?? ajout??(e) en tant qu'utilisateur enregistr?? sur My Website. "), "Looking at string: " + decodedEmailContent);
            decodedEmailSubject = ConvertEmailSubjectFromBase64ToUnicode(emailContent, emailFileName);
            Assert.IsTrue(decodedEmailSubject.Contains("Confirmation d'inscription sur  My Website"));
        }

        [Test]
        public void DNN_12337_No_Message_Goes_To_User_When_Security_Role_Is_Edited()
        {
            //Arrange
            SetUpTestForInstall();
            RunAutoInstall();
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);

            //Delete any files in the test EmailAddress folder
            homePage.DeleteFilesInTestEmails();

            //Edit the web.config file so that Emails are sent to a local folder
            WebConfigManager.UpdateConfig(PhysicalPath);

            //Act 
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/Host/Host%20Settings.aspx");
            HostSettingsPage hostSettings = new HostSettingsPage(homePage);
            hostSettings.SetSMTPSettings("support@dnn.com", "localhost");
            System.Threading.Thread.Sleep(1500);

            ieInstance.GoTo(SiteURL + "/Admin/UserAccounts.aspx");
            UserPage userPage = new UserPage(homePage);
            userPage.AddUser(TestUsers.User1.UserName, TestUsers.User1.Password, TestUsers.User1.FirstName, TestUsers.User1.LastName, TestUsers.User1.EmailAddress, TestUsers.User1.DisplayName);
            System.Threading.Thread.Sleep(1000);

            ieInstance.GoTo(SiteURL + "/Admin/SecurityRoles.aspx");
            SecurityRolesPage rolesPage = new SecurityRolesPage(homePage);
            rolesPage.AddRole("Test Role");
            //Delete any files in the test EmailAddress folder
            homePage.DeleteFilesInTestEmails();
            System.Threading.Thread.Sleep(1000);
            rolesPage.AddUserToRole("Test Role", TestUsers.User1.DisplayName);
            System.Threading.Thread.Sleep(1000);

            //Assert
            //Check that an email was sent 
            String emailFileName = null;
            String emailContent = null;
            int emailFilePosition = 0;
            for (int i = 0; i < Directory.GetFiles(TestEmailPath).Length; i++)
            {
                emailFileName = Directory.GetFiles(TestEmailPath)[i];
                emailContent = File.ReadAllText(emailFileName);
                if (emailContent.Contains("X-Receiver: " + TestUsers.User1.DisplayName) && emailContent.Contains("X-Sender: " + TestUsers.Admin.Email))
                {
                    emailFilePosition = i;
                }
            }
            //View admin email content
            emailFileName = Directory.GetFiles(TestEmailPath)[emailFilePosition];
            emailContent = File.ReadAllText(emailFileName);
            String decodedEmailContent = ConvertEmailContentFromBase64ToUnicode(emailContent, emailFileName);
            Assert.IsTrue(decodedEmailContent.Contains("Dear " + TestUsers.User1.DisplayName), "Looking at string: " + decodedEmailContent);
            Assert.IsTrue(decodedEmailContent.Contains("Your user account at My Website has been recently updated to include access to the following Security Role:"), "Looking at string: " + decodedEmailContent);
            Assert.IsTrue(decodedEmailContent.Contains("Role: Test Role"),"Looking at string: " + decodedEmailContent);
            String decodedEmailSubject = ConvertEmailSubjectFromBase64ToUnicode(emailContent, emailFileName);
            Assert.IsTrue(decodedEmailSubject.Contains("My Website User Account Update"));
        }

        [Test]
        public void DNN_12376_View_Profile_Error_With_Portals_Languages()
        {
            //Arrange
            SetUpTestForInstall();
            RunAutoInstall();
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);

            //Act
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/Admin/Extensions.aspx");
            ExtensionsPage extensionsPage = new ExtensionsPage(homePage);
            extensionsPage.InstallExtension(LanguagePath);

            //Disable the new language
            ieInstance.GoTo(SiteURL + "/Admin/Languages.aspx");
            LanguagePage languagePage = new LanguagePage(homePage);
            System.Threading.Thread.Sleep(1000);
            languagePage.GetCheckBoxForLanguage(EnglishLocaleName, "Enabled").Checked = false;
            System.Threading.Thread.Sleep(1000);

            //Create a Portal
            ieInstance.GoTo(SiteURL + "/Host/Portals.aspx");
            HostPortalPage portalPage = new HostPortalPage(homePage);
            portalPage.AddChildPortal(ApplicationName, "Child Portal", "ChildPortal");
            ieInstance.GoTo(SiteURL + "/ChildPortal/Admin/Languages.aspx");
            languagePage.SelectAndUpdateNewDefaultLanguage(LocaleName, "rcbItem ");
            System.Threading.Thread.Sleep(1500);
            languagePage.GetCheckBoxForLanguage("English (United States)", "Enabled").Checked = false;

            //Log out of the child portal
            ieInstance.GoTo(SiteURL + "/ChildPortal");
            loginPage.LogoffUser();
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
            loginPage.RegisterLink.Click();

            //Assert
            Assert.IsFalse(homePage.ContentPane.InnerHtml.Contains("Error"));
            Assert.IsFalse(homePage.ErrorImage.Exists);
        }

        [Test]
        public void DNN_12378_Telerik_Uploading_Images()
        {
            //Arrange
            SetUpTestForInstall();
            RunAutoInstall();
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);

            //Act 
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            HTMLModule htmlModule = new HTMLModule(homePage);
            htmlModule.EditModuleContentLink.Click();
            htmlModule.TelerikEditor.ContentImageManagerLink.Click();
            System.Threading.Thread.Sleep(2000);
            htmlModule.TelerikEditor.TelerikNewFolderIcon.Click();
            System.Threading.Thread.Sleep(1000);
            htmlModule.TelerikEditor.TelerikNewFolderNameField.Value = "Test Folder";
            htmlModule.TelerikEditor.TelerikCreateNewFolderLink.Click();
            System.Threading.Thread.Sleep(2000);
            Assert.IsTrue(htmlModule.TelerikEditor.TelerikFolderDialog.InnerHtml.Contains("Test Folder"));
            htmlModule.TelerikEditor.FindPopUpFolderSpanByFolderName("Test Folder").Click();
            System.Threading.Thread.Sleep(2000);
            htmlModule.TelerikEditor.TelerikNewFolderIcon.Click();
            System.Threading.Thread.Sleep(1000);
            htmlModule.TelerikEditor.TelerikNewFolderNameField.Value = "Img";
            htmlModule.TelerikEditor.TelerikCreateNewFolderLink.Click();
            System.Threading.Thread.Sleep(1000);
            Assert.IsTrue(htmlModule.TelerikEditor.TelerikFolderDialog.InnerHtml.Contains("Img"));
            htmlModule.TelerikEditor.FindPopUpFolderSpanByFolderName("Img").Click();

            //Upload an image
            htmlModule.TelerikEditor.UploadImageLink.Click();
            htmlModule.TelerikEditor.DocumentFileUpload.Set(ImagePath);
            htmlModule.TelerikEditor.UploadImageButton.Click();
            System.Threading.Thread.Sleep(1500);
            
            //Assert
            Assert.IsTrue(htmlModule.TelerikEditor.FolderContentsTable.InnerHtml.Contains(ImageName));
            htmlModule.TelerikEditor.TelerikCancelButton.Click();
        }

        [Test]
        public void DNN_12398_Photo_Profile_Data_Type_Hard_Coded_PortalID_Of_0()
        {
            //Arrange
            SetUpgradeVersionAndType("523", "1");
            SetUpSiteForUpgrade();

            //Shut down Ie
            ieInstance.GoTo(SiteURL + "/LogOff.aspx");
            WatiNUtil.CloseIEInstance(ieInstance);

            //Act
            //Run the upgrade
            RunUpgrade();
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);

            //Create a Child Portal
            ieInstance.GoTo(SiteURL + "/Host/Portals.aspx");
            HostPortalPage portalPage = new HostPortalPage(homePage);
            portalPage.AddChildPortal(ApplicationName, "Child Portal", "ChildPortal");

            //Add profile property to child portal
            ieInstance.GoTo(SiteURL + "/ChildPortal/Admin/UserAccounts.aspx");
            UserPage userPage = new UserPage(homePage);
            userPage.ManageProfilePropertiesLink.Click();
            ProfilePropertiesPage propertiesPage = new ProfilePropertiesPage(homePage);
            propertiesPage.AddNewProfilePropertyLink.Click();
            propertiesPage.PropertyNameField.Value = "TestImage";
            propertiesPage.DataTypeSelectList.Select("Image");
            propertiesPage.PropertyCategoryField.Value = "Test Property";
            propertiesPage.NextButton.Click();
            propertiesPage.ReturnToProfilePropertiesLink.Click();
            Assert.IsTrue(propertiesPage.PropertyTable.InnerHtml.Contains("TestImage"));
            TableRow propertyRow = propertiesPage.GetPropertyRow("TestImage");
            Assert.IsNotNull(propertyRow);
            Assert.IsTrue(propertiesPage.GetPropertyDataTypeCell(propertyRow).InnerHtml.Contains("Image"));
            
            //Add profile property to parent portal
            ieInstance.GoTo(SiteURL + "/Admin/UserAccounts.aspx");
            userPage.ManageProfilePropertiesLink.Click();
            propertiesPage.AddNewProfilePropertyLink.Click();
            propertiesPage.PropertyNameField.Value = "TestImage";
            propertiesPage.DataTypeSelectList.Select("Image");
            propertiesPage.PropertyCategoryField.Value = "Test Property";
            propertiesPage.NextButton.Click();
            propertiesPage.ReturnToProfilePropertiesLink.Click();
            Assert.IsTrue(propertiesPage.PropertyTable.InnerHtml.Contains("TestImage"));
            propertyRow = propertiesPage.GetPropertyRow("TestImage");
            Assert.IsNotNull(propertyRow);
            Assert.IsTrue(propertiesPage.GetPropertyDataTypeCell(propertyRow).InnerHtml.Contains("Image"));
            
            //Add Superuser profile property 
            ieInstance.GoTo(SiteURL + "/Host/SuperUser%20Accounts.aspx");
            userPage.ManageProfilePropertiesLink.Click();
            propertiesPage.AddNewProfilePropertyLink.Click();
            propertiesPage.PropertyNameField.Value = "TestImage";
            propertiesPage.DataTypeSelectList.Select("Image");
            propertiesPage.PropertyCategoryField.Value = "Test Property";
            propertiesPage.NextButton.Click();
            propertiesPage.ReturnToProfilePropertiesLink.Click();
            Assert.IsTrue(propertiesPage.PropertyTable.InnerHtml.Contains("TestImage"));
            propertyRow = propertiesPage.GetPropertyRow("TestImage");
            Assert.IsNotNull(propertyRow);
            Assert.IsTrue(propertiesPage.GetPropertyDataTypeCell(propertyRow).InnerHtml.Contains("Image"));
        }

        [Test]
        public void DNN_12518_Failure_To_Filter_For_HtmlScript_In_Messaging_Module()
        {
            //Arrange
            SetUpTestForInstall();
            RunAutoInstall();
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);

            //Act
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);

            //Add a user 
            ieInstance.GoTo(SiteURL + "/Admin/UserAccounts.aspx");
            UserPage userPage = new UserPage(homePage);
            userPage.AddUser(TestUsers.User1.UserName, TestUsers.User1.Password, TestUsers.User1.FirstName, TestUsers.User1.LastName, TestUsers.User1.EmailAddress, TestUsers.User1.DisplayName);
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            loginPage.LogoffUser();
            loginPage.LoginUser(TestUsers.User1.UserName, TestUsers.User1.Password);

            loginPage.RegisterLink.Click();
            MessagingModule messagingModule = new MessagingModule(homePage);
            messagingModule.ComposeLink.Click();
            messagingModule.ToTextField.TypeText(TestUsers.User1.UserName);
            messagingModule.ValidateUserLink.Click();
            Assert.IsTrue(messagingModule.MessageSpan.InnerHtml.Contains("Username '" + TestUsers.User1.UserName + "' is valid"));
            messagingModule.SubjectTextField.TypeText("<script>alert(‘hacked’);</script>");
            System.Threading.Thread.Sleep(1000);
            messagingModule.HTMLEditorModeSpan.Click();
            System.Threading.Thread.Sleep(500);
            messagingModule.htmlField.TypeText("&lt;script&gt;alert(&lsquo;hacked&rsquo;);&lt;/script&gt;");
            messagingModule.SendLink.Click();

            //Assert
            System.Threading.Thread.Sleep(2500);
            Assert.IsTrue(messagingModule.GetMsgRowBySubject("<script>alert(‘hacked’);</script>").Exists);
            messagingModule.GetMsgLinkBySubject("<script>alert(‘hacked’);</script>").Click();
            Assert.IsTrue(messagingModule.MsgContentSpan.Text.Contains("<script>alert(‘hacked’);</script>"));
        }

        [Test]
        public void DNN_11961_Button_Save_Resource_File_In_Language_Editor_Returns_To_Languages_List()
        {
            //Arrange
            SetUpTestForInstall();
            RunAutoInstall();
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);

            //Act 
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/Admin/Languages.aspx");
            LanguagePage languagePage = new LanguagePage(homePage);
            languagePage.GetHostLanguageEditButton("English (United States)").Click();
            languagePage.AdminStringTextField.Value = "New Admin Value";
            languagePage.SaveResourceFileLink.Click();
            System.Threading.Thread.Sleep(2000);

            //Assert
            SiteMenu menu = new SiteMenu(homePage);
            Assert.IsTrue(menu.BreadCrumbSpan.InnerHtml.Contains("Languages"));
            Assert.IsTrue(languagePage.ModuleTitleSpan.InnerHtml.Contains("Language Editor"));
            Assert.IsTrue(languagePage.ModuleTitleSpans.Count == 1);
            Assert.IsTrue(languagePage.AdminStringTextField.Value == "New Admin Value");

            //Navigate away, and back to the page 
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            System.Threading.Thread.Sleep(500);
            ieInstance.GoTo(SiteURL + "/Admin/Languages.aspx");
            languagePage.GetHostLanguageEditButton("English (United States").Click();

            Assert.IsTrue(languagePage.AdminStringTextField.Value.Equals("New Admin Value"));
        }

        [Test]
        public void DNN_11726_Upgrade_462_To_530_Alpha_Failes_With_Compiler_Error_Indirect_Reference()
        {
            //Arrange
            SetUpgradeVersionAndType("462", "3");
            SetUpSiteForUpgrade();
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);

            //Act
            ieInstance.Close();
            RunCommunity523Upgrade();
            ieInstance.Close();
            RunUpgrade();

            //Assert
            //Log in
            homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            //View the Event Viewer
            ieInstance.GoTo(SiteURL + "/Admin/LogViewer.aspx");
            EventViewerPage eventViewer = new EventViewerPage(homePage);
            Assert.IsFalse(eventViewer.LogViewerTable.InnerHtml.Contains("General Exception"));
        }

        [Test]
        public void DNNPro_12130_Open_Document_File_Extension_Needs_To_Be_Added_To_Framework()
        {
            //Arrange
            SetUpProTestForInstall();
            RunAutoInstall();
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
 
            //Act 
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/Host/Host%20Settings.aspx");
            HostSettingsPage hostSettingsPage = new HostSettingsPage(homePage);
            hostSettingsPage.OtherSettingsExpandButton.Click();
            
            //Assert
            Assert.IsTrue(hostSettingsPage.AllowableFileExtensions.Text.Contains(",template"));
        }

        [Test]
        public void DNNPro_12131_Copyright_Date_Needs_Updating_for_Open_Document_Module()
        {
            //Arrange
            SetUpProTestForInstall();
            RunAutoInstall();
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
 
            //Act 
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/Admin/Extensions.aspx");
            ExtensionsPage extensionsPage = new ExtensionsPage(homePage);
            extensionsPage.FilterByTypeSelectList.Select("Module");
            extensionsPage.GetExtensionEditButton("Document Library").Click();
            System.Threading.Thread.Sleep(2000);

            //Get Date 
            DateTime dateTime = DateTime.Now;
            int currentYear = dateTime.Year;
            string copyrightString = "Copyright (c) 2002-" + currentYear;

            //Assert
            Assert.IsTrue(extensionsPage.LicenseDiv.InnerHtml.Contains(copyrightString));
        }


        #endregion

        private string ConvertEmailSubjectFromBase64ToUnicode(string emailContent, string emailFileName)
        {
            //Separate the EmailAddress subject from the EmailAddress information
            string contentLineRegex = "(?<=Subject:).*";
            Match match = Regex.Match(@emailContent, contentLineRegex);
            Assert.IsTrue(match.Success, "Could not find subject Line! Looking in file: " + emailFileName);

            //Convert the EmailAddress content
            emailContent = match.Value;
            emailContent = emailContent.Replace(" ", "");
            emailContent = emailContent.Replace("=?utf-8?B?", "");
            emailContent = emailContent.Replace("?=", "");
            byte[] b = null;
            try
            {
                 b = System.Convert.FromBase64String(emailContent);
            }
            catch (Exception e)
            {
                Gallio.Framework.TestLog.Write("Exception while converting from base 64: " + emailContent + Environment.NewLine + e);
            }
            String decodedEmailSubject = System.Text.ASCIIEncoding.ASCII.GetString(b);
            return decodedEmailSubject;
        }


        private string ConvertEmailContentFromBase64ToUnicode(string emailContent, string emailFileName)
        {
            //Replace any new link characters
            emailContent.Replace(Environment.NewLine, " ");

            //Separate the EmailAddress content from the EmailAddress information
            string contentLineRegex = "(?<=base64).*$";
            Match match = Regex.Match(@emailContent, contentLineRegex, RegexOptions.Singleline);
            Assert.IsTrue(match.Success, "Could not find content Line! Looking in file: " + emailFileName);

            //Convert the EmailAddress content
            emailContent = match.Value;
            byte[] b = null;
            try
            {
                b = System.Convert.FromBase64String(emailContent);
            }
            catch (Exception e)
            {
                Gallio.Framework.TestLog.Write("Exception while converting from base 64: " + emailContent + Environment.NewLine + e);
            }
            String decodedEmailContent = System.Text.ASCIIEncoding.ASCII.GetString(b);
            return decodedEmailContent;
        }


        private void SelectRibbonBarAsControlPanelStyle(string hostEmail, WatiNBase homePage)
        {
            HostSettingsPage hostSettings = new HostSettingsPage(homePage);
            hostSettings.HostEmailTextField.Value = hostEmail;
            hostSettings.OtherSettingsExpandButton.Click();
            hostSettings.ControlPanelStyleSelectList.Select("RIBBONBAR");
            hostSettings.UpdateLink.Click();
            System.Threading.Thread.Sleep(1000);
        }


    }
}